
package com.hyfrogx.config;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.hyfrogx.common.utils.SpringContextUtils;
import com.hyfrogx.modules.zoom.service.MeetJoinPriceService;
import com.hyfrogx.modules.zoom.service.MeetPriceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;

/**
 * @author ：Li9527
 * @date ：Created in 2019-04-01 17:17
 * @description：项目启动就执行的工具类
 * @modified By：
 * @version: 1.0
 */
@Component
public class InitConfig implements InitializingBean {

    @Autowired
    ZoomConfig zoomConfig;

    @Autowired
    ImInfoConfig imInfoConfig;

    @Autowired
    TencentConfig tencentConfig;

    @Autowired
    ResourceConfig resourceConfig;

    @Autowired
    WxpaysConfig wxPaysConfig;

    @Autowired
    AliPayConfig aliPayConfig;

    @Autowired
    MeetPriceService meetPriceService;

    @Autowired
    MeetJoinPriceService meetJoinPriceService;

    @Override
    public void afterPropertiesSet() throws Exception {
//        log.info("开始加载init");
//        log.info("当前读取配置为：" + SpringContextUtils.getActiveProfile());
//        log.info("im配置");
        reflect(imInfoConfig);
//        log.info("文件存储路径配置");
//        reflect(resourceConfig);
//        log.info("腾讯云配置");
        reflect(tencentConfig);
//        log.info("zoom配置");
        reflect(zoomConfig);
//        log.info("微信支付配置");
        reflect(wxPaysConfig);
//        log.info("支付宝支付配置");
        reflect(aliPayConfig);
//        log.info("结束..");
        meetPriceService.init();
        meetJoinPriceService.init();
    }

    public static void reflect(Object o) throws Exception{
        Class cls = o.getClass();
        Field[] fields = cls.getDeclaredFields();
        for(int i=0; i<fields.length; i++){
            Field f = fields[i];
            f.setAccessible(true);
//            log.info(f.getName() + "----:" + f.get(o));
        }
    }
}